import Vue from 'vue'
import VeeValidate, { Validator } from 'vee-validate'
import zh from 'vee-validate/dist/locale/zh_CN' // 引入中文文件
Validator.addLocale(zh)
const config = {
    locale: 'zh_CN',
    fieldsBagName: 'fieldBags'
}
Vue.use(VeeValidate, config)

// 自定义validate
const dictionary = {
    zh_CN: {
        messages: {
            required: (field) => '请' + field,
            number: (field) => field + '必须为数值',
        },
        attributes: {
            mobile: '输入手机号码',
            code: '输入验证码',
            msgCode: '输入短信验证码',
        }
    }
}
Validator.updateDictionary(dictionary)

// 1.图形验证码
Validator.extend('code', {
    messages: {
        zh_CN: field => '验证码格式不正确'
    },
    validate: value => {
        return /^[A-Za-z0-9]{4}$/.test(value)
    }
})

//2.短信验证码
Validator.extend('msgCode', {
    messages: {
        zh_CN: field => '短信验证码格式不正确'
    },
    validate: value => {
        return /^[0-9]{6}$/.test(value)
    }
})

// 3.手机号码
Validator.extend('mobile', {
    messages: {
        zh_CN: field => '手机号码格式不正确'
    },
    validate: value => {
        return /^1[3456789]\d{9}$/.test(value)
    }
})

